﻿@using Kaiser.Cubic.Service
@{
   
    Layout = "/Views/Shared/_Layout.cshtml";
}
@using Kaiser.Extensions;
@{
    var service = new CubicServiceClient();
    string categoryId = Request["categoryId"] ?? "1";
    var curCategory = service.GetProductCategory(categoryId) ?? new ProductCategory();

    ViewBag.Title =   curCategory.name;

    ProductDetail[] productList = service.GetProductsByCategoryCode(categoryId);

    if (productList.Count() == 1)
    {
        Response.Redirect(Url.Action("ProductDetail", "Product") + "?id=" + productList.FirstOrDefault().ProductId);
    }

   
}

<script type="text/javascript" src="/Scripts/jquery.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery.pagination.js"></script>
<script type="text/javascript">
    $(function () {
        var num_entries = $("#hiddenresult div.swmming_all").length;
        //回调函数的作用是显示对应分页的列表项内容
        //回调函数在用户每次点击分页链接的时候执行
        //参数page_index{int整型}表示当前的索引页
        var initPagination = function () {
            // 创建分页
            $("#Pagination").pagination(num_entries, {
                num_edge_entries: 2, //边缘页数
                num_display_entries: 20, //超连接显示数
                callback: pageselectCallback,
                items_per_page: 5, //每页显示3项
                prev_text: "Pre",
                next_text: "Next"
            });
        }();

        function pageselectCallback(pageIndex, jq) {
            // 从表单获取每页的显示的列表项数目
            var itemsPerPage = 5;
            var maxElem = Math.min((pageIndex + 1) * itemsPerPage, num_entries);

            $("#Searchresult").html("");
            // 获取加载元素
            for (var i = pageIndex * itemsPerPage; i < maxElem; i++) {

                $("#Searchresult").append($("#hiddenresult .swmming_all:eq(" + i + ")").clone());
            }
            //阻止单击事件
            return false;
        }


    });
</script>
<div class="index_center">
    <div class="bg"></div>
    <div class="conBg">
         @RenderPage("/Views/Shared/Menu.cshtml")
        <div class="erBanner">
            <a href="#">
                <img src="/images/News_03.png" /></a>

        </div>
        <div class="ercon">
            <div class="erconTitle"><a href="/">Home</a><span>></span><a href="#">Products</a><span>></span><em>Swimming Pool Heat Pump</em></div>
            <div class="erLeft">
                <div class="erLeftTitle">Products</div>
                <div class="erLeft_1">
                                        @Html.Partial("ProductTreeMenu")
                </div>
            </div>
            <div class="erRight">
                <div class="erRightTitle">@curCategory.CategoryName</div>

                <div class="swmming">
                    <div id="hiddenresult" style="display: none;">
                        @foreach (var item in productList)
                        {
                            <div class="swmming_all">
                                <div class="swmming_pic">
                                    <a href="@Url.Action("ProductDetail")?Id=@item.ProductId">
                                        <img src="@item.ProductPic" /></a>
                                </div>
                                <div class="swmming_name"><a href="@Url.Action("ProductDetail")?Id=@item.ProductId">@item.ProductName</a></div>
                                <div class="swmming_word">@(new HtmlString(System.Web.HttpContext.Current.Server.UrlDecode(item.EnglishDehumidifierDescription).CleanHtmlTags().Substr(260))) </div>
                            </div>
                        }
                        @*<div class="erFen"><a href="#">上一页</a><span>1</span><a href="#">2</a><a href="#">3</a><a href="#">4</a><em>...</em><a href="#">20</a><a href="#">下一页</a></div>*@
                    </div>
                    <div id="Searchresult">分页初始化完成后这里的内容会被替换。</div>
                    <div id="Pagination" class="erFen"></div>
                </div>
            </div>
        </div>
        @RenderPage("/Views/Shared/Foot.cshtml")
    </div>
</div>

